/*
 * Texture.cpp
 *
 *  Created on: 2011/07/06
 *      Author: naoki
 */

#include "NTEngine/NTEngine.h"
#include "Graphics/src/TextureImpl.h"

namespace NTEngine {
namespace Graphics {

Texture Texture::create( Xml::ConstElement e, const char* path ) {
	Texture ret;
	ret.mImpl = NEW Impl( e, path );
	return ret;
}

Texture Texture::create( const char* fileName ) {
	Texture ret;
	ret.mImpl = NEW Impl( fileName );
	return ret;
}

Texture Texture::create( int w, int h, bool createMipChain ) {
	Texture ret;
	ret.mImpl = NEW Impl( w, h, createMipChain );
	return ret;
}

Texture Texture::create( const char* fileData, int fileSize ) {
	Texture ret;
	ret.mImpl = NEW Impl( fileData, fileSize );
	return ret;
}

void Texture::lock( unsigned** surface, int* pitch, int level ) {
	ASSERT( mImpl );
	mImpl->lock( surface, pitch, level );
}

void Texture::lock( unsigned** surface, int* pitch, int x, int y, int w, int h, int level ) {
	ASSERT( mImpl );
	mImpl->lock( surface, pitch, x, y, w, h, level );
}

void Texture::unlock( int level ) {
	ASSERT( mImpl );
	mImpl->unlock( level );
}

const char* Texture::name() const {
	return mImpl->mName;
}

int Texture::width() const {
	ASSERT( mImpl );
	return mImpl->width();
}

int Texture::height() const {
	ASSERT( mImpl );
	return mImpl->height();
}

int Texture::originalWidth() const {
	ASSERT( mImpl );
	return mImpl->originalWidth();
}

int Texture::originalHeight() const {
	ASSERT( mImpl );
	return mImpl->originalHeight();
}

bool Texture::isReady() {
	ASSERT( mImpl );
	return mImpl->isReady();
}

bool Texture::isError() const {
	ASSERT( mImpl );
	return mImpl->isError();
}

Texture::Texture( const Impl* ) : mImpl( 0 ) { //ヌルポからの自動生成
}

bool Texture::operator <( const Texture& a ) const {
	return ( mImpl < a.mImpl );
}

#define TYPE Texture
#include "NTEngine/Base/Impl/ReferenceCounterTemplate.h"

} // namespace Graphics
} // namespace NTEngine
